import logging
import json
import hashlib
from datetime import datetime
from django.utils.encoding import smart_unicode
from common.exe_web_settings import db as  exe_settings
from common.utils.decorator import response_wrapper
from common.utils.exceptions import ParamError
from common.utils.tz import local_now
from django.views.decorators.http import require_POST, require_GET
from common.cache import redis_cache

_LOGGER = logging.getLogger('hydra')

@require_GET
@response_wrapper
def get_settings(req):
    query_dct = req.GET.dict()
    if query_dct == {}:

        items, total = exe_settings.get_settings(query_dct)
        sett_items = []

        for item in items:
            data = item.as_dict()
            sett_items.append(data)
        return {'list': sett_items, 'page': query_dct.get('$page', 1),
                'size': len(sett_items), 'total_count': total}
    else:
        data = exe_settings.get_exe_active_settings(query_dct['bank'])
    if data:
        return data
    else: return  {}